<?php
/**
 * Created by PhpStorm.
 * User: winleung
 * Date: 2019-10-22
 * Time: 23:11
 */

namespace app\api\model;


use think\Db;
use think\Exception;
use think\Model;

class Pharmacy extends Model
{
    protected $table = 'pharmacy_account';

    public function createPharmacyAccount($params)
    {
        $insertData = [
            'pharmacy_name' => $params['pharmacy_name'],
            'pharmacy_mobile_phone' => $params['phone'],
            'pharmacy_tel_phone' => $params['pharmacy_tel_phone'],
            'password' => $params['password'],
            'description' => $params['description'],
            'longitude' => $params['longitude'],
            'latitude' => $params['latitude'],
            'avatar' => $params['avatar'],
            'business_license_img' => isset($params['business_license_img']) ? $params['business_license_img'] : '',
            'licensed_pharmacist_license_img' => isset($params['licensed_pharmacist_license_img']) ? $params['licensed_pharmacist_license_img'] : '',
            'drug_trading_license_img' => isset($params['drug_trading_license_img']) ? $params['drug_trading_license_imgd'] : '',
            'check_status' => 1,
        ];

        $result = Db::name($this->table)->insertGetId($insertData);

        return 0 < $result;
    }

    /**
     * 根据账号查询登陆密码
     */
    public function queryPasswordByAccount($pharmacyMobilePhone)
    {
        $pharmacyInfo = null;
        try {
            $pharmacyInfo = Db::name($this->table)
                ->where('pharmacy_mobile_phone', $pharmacyMobilePhone)
                ->where('check_status', 'in', '1,2,3')
                ->find();
        } catch (Exception $e) {
            throwBusinessException("店铺不存在");
        }

        return $pharmacyInfo;
    }

    public function getPharmacyInfoById($param)
    {
        $pharmacyInfo = null;
        try {
            $pharmacyInfo = Db::name($this->table)
                ->where('id', $param['pharmacy_id'])
                ->where('check_status', 'in', '1,2,3')
                ->find();
        } catch (Exception $e) {
            throwBusinessException("店铺不存在");
        }

        return $pharmacyInfo;
    }

}